/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.googlecode.jsimplemarket.wicket.pages;

import com.googlecode.jsimplemarket.model.NStareCantar;
import com.googlecode.jsimplemarket.model.NStareCreanta;
import com.googlecode.jsimplemarket.model.NStareSpatiuComercial;
import com.googlecode.jsimplemarket.model.NTipAlarma;
import com.googlecode.jsimplemarket.model.NTipDataContact;
import com.googlecode.jsimplemarket.model.NTipRecurenta;
import com.googlecode.jsimplemarket.model.NTipSpatiuComercial;
import com.googlecode.jsimplemarket.model.NTipTaxa;
import com.googlecode.jsimplemarket.model.Taxa;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.Link;
import org.springframework.security.core.GrantedAuthority;

/**
 *
 * @author Alexandru.Codescu
 */
public class NomenclatoarePage extends DefaultPageTemplate {
    private Link createNavigationLink(String id, final WebPage page, String... roles) {
        Link link = new Link(id) {
            @Override
            public void onClick() {
                setResponsePage(page);
            }
        };
        boolean visible = false;
        for (GrantedAuthority authority: getUtilizator().getAuthorities()) {
            for (String role : roles) {
                if (authority.getAuthority().equalsIgnoreCase(role)) {
                    visible = true;
                    break;
                }
            }
            if (visible) {
                break;
            }
        }
        
        link.setVisible(visible);
        return link;
    }
    
    public NomenclatoarePage() {
        Link linkTipAlarma = createNavigationLink("tipAlarma", new NomenclatorViewPage(NTipAlarma.class), "ROLE_ADMIN");
        Link linkTipDateContact = createNavigationLink("tipDateContact", new NomenclatorViewPage(NTipDataContact.class), "ROLE_ADMIN");
        Link linkStareCantar = createNavigationLink("stareCantar", new NomenclatorViewPage(NStareCantar.class), "ROLE_ADMIN");
        Link linkStareCreanta = createNavigationLink("stareCreanta", new NomenclatorViewPage(NStareCreanta.class), "ROLE_ADMIN");
        Link linkTipSpatiu = createNavigationLink("tipSpatiu", new NomenclatorViewPage(NTipSpatiuComercial.class), "ROLE_ADMIN");
        Link linkStareSpatiu = createNavigationLink("stareSpatiu", new NomenclatorViewPage(NStareSpatiuComercial.class), "ROLE_ADMIN");
        Link linkTipRecurenta = createNavigationLink("tipRecurenta", new NomenclatorViewPage(NTipRecurenta.class, TipRecurentaEditPage.class), "ROLE_ADMIN");
        Link linkTipTaxa = createNavigationLink("tipTaxa", new NomenclatorViewPage(NTipTaxa.class, TipTaxaEditPage.class), "ROLE_ADMIN");
        Link linkTaxe = createNavigationLink("taxe", new NomenclatorViewPage(Taxa.class, TaxaEditPage.class), "ROLE_ADMIN");
        
        add(linkTipAlarma, linkTipDateContact, linkStareCantar, 
                linkStareCreanta, linkTipSpatiu, linkStareSpatiu,
                linkTipRecurenta, linkTipTaxa, linkTaxe);
    }
}
